package com.stox.ui.javafx.core.event.handler;

import javafx.geometry.Bounds;
import javafx.scene.Node;

import com.stox.ui.javafx.core.widget.StoxStage;

public class BoundsInParentPropertyChangeListener extends AbstractPropertyChangeListener<Bounds> {
	
	public BoundsInParentPropertyChangeListener(Node node) {
		super(node);
	}

	@Override
	public void changed(Bounds newValue, Node node) {
		Bounds paneBounds = StoxStage.getContentPane().getBoundsInParent();
		
		if(newValue.getMinX() < paneBounds.getMinX())
			node.setLayoutX(paneBounds.getMinX());
		if(newValue.getMaxX() > paneBounds.getMaxX())
			node.setLayoutX(paneBounds.getMaxX() - newValue.getWidth());
		if(newValue.getMinY() < paneBounds.getMinY())
			node.setLayoutY(paneBounds.getMinY());
		if(newValue.getMaxY() > paneBounds.getMaxY())
			node.setLayoutY(paneBounds.getMaxY() - newValue.getHeight());
	}
	
}
